package vip.zhenzicheng.jvm.jvmbook.part2;

/**
 * 无法创建新线程导致OOM
 * VM Args：-Xss2M
 *
 * @author zhenzicheng
 * @date 2022-07-17 14:14
 */
public class JavaVMStackOOM {

  private void dontStop() {
    while (true) {
    }
  }

  public void stackLeakByThread() {
    while (true) {
      Thread thread = new Thread(() -> {
        dontStop();
      });
      thread.start();
    }
  }

  public static void main(String[] args) {
    JavaVMStackOOM oom = new JavaVMStackOOM();
    oom.stackLeakByThread();
  }
}
